package org.example.builderPattern;

import java.util.function.Function;

/**
 * @Author : 叶荻风
 * @create : 2024/6/7 11:10
 */
//目标类
public class RabbitMqClient {

    private RabbitMqClient(Builder builder){
        //init connecr
        System.out.println("创建连接 : "+builder.getExchange()+builder.getHost()+builder.getNum());
    };

    public void sendMessage(String message){
        System.out.println("send "+message);
    }

    public static class Builder implements MyBuilder<RabbitMqClient>{
        private String host = "ad";
        private String exchange = "sda";
        private String queue = "adf";

        private int num = 0;
        public Builder setHost(String host) {
            this.host = host;
            return this;
        }

        public Builder setExchange(String exchange) {
            this.exchange = exchange;
            return this;
        }

        public Builder setQueue(String queue) {
            this.queue = queue;
            return this;
        }

        public String getHost() {
            return host;
        }

        public int getNum() {
            return num;
        }

        public Builder setNum(Function<Builder,Integer> fc) {
            this.num = fc.apply(new Builder());
            return this;
        }

        public String getExchange() {
            return exchange;
        }

        public String getQueue() {
            return queue;
        }

        @Override
        public RabbitMqClient build() {
            return new RabbitMqClient(this);
        }
    }
}
